package AEF::SourceGrabber;

use Modern::Perl;
use Moose;

require AEF::AEFProcessor;

extends 'AEF::AEFProcessor';

has 'source' => (
	is => 'rw', 
	isa => 'Str', 
);

has 'first' => (
    is => 'rw',
    isa => 'Bool',
    default => 1,
);

has '+typeFormats' => (
	default => sub { 
		{
			0x41 => 'Z*',
		};
	}
);

around 'RequireDataForType' => sub
{
	my $orig = shift;
	my $self = shift;
	my $type = shift;

	my $require = $self->$orig($type);
	if($require)
	{
		if($type != 0x41)
		{
			$require = 0;
		}
		if($type == 0x20 || $type == 0x40)
		{
            if(!$self->first)
            {
                $self->doneProcessing(1);
            }
            else
            {
                $self->first(0);
            }
		}
	}
	return $require;
};

override 'ProcessBlock' => sub 
{
	my $self = shift;
	my ($type, $data_chunk, $ptr) = @_;
	given($type)
	{
		when(0x41)
		{
			my ($source) = $data_chunk;
			$self->source($source);
		}
	}
};


1;

no Moose;

